package com.scrx.ymg.action;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.scrx.ymg.util.BaseUtil;
import com.scrx.ymg.util.PayConfigUtil;


public class StartGateServiceData implements ServletContextListener  {
	public void contextDestroyed(ServletContextEvent arg0) {
		System.out.println("关闭");
		
	}
	public void contextInitialized(ServletContextEvent arg0) {
		System.out.println("启动加载默认文档数据！");
		 File file = new File(this.getClass().getClassLoader().getResource("").getPath()+"secret.txt");
		 StringBuilder result = new StringBuilder();
	        try{
	            BufferedReader br = new BufferedReader(new FileReader(file));//构造一个BufferedReader类来读取文件
	            String s = null;
	            while((s = br.readLine())!=null){//使用readLine方法，一次读一行
	                result.append(System.lineSeparator()+s);
	            }
	            br.close();
	        }catch(Exception e){
	            e.printStackTrace();
	        }
	        String temp=result.toString();
	        PayConfigUtil.APPID=BaseUtil.getJsonString(temp, "APPID");
	        PayConfigUtil.SECRET=BaseUtil.getJsonString(temp, "SECRET");
	        PayConfigUtil.MCH_ID=BaseUtil.getJsonString(temp, "MCH_ID");
	        PayConfigUtil.API_KEY=BaseUtil.getJsonString(temp, "API_KEY");
	        PayConfigUtil.Template_ID=BaseUtil.getJsonString(temp, "Template_ID");
	        BaseUtil.ProductPath=BaseUtil.getJsonString(temp, "ProductPath");
	        BaseUtil.QRCode=BaseUtil.getJsonString(temp, "QRCode");
	        PayConfigUtil.ZY_URL=BaseUtil.getJsonString(temp, "HD_URL")+PayConfigUtil.ZY_URL;
	        LogisticsAction.EBusinessID=BaseUtil.getJsonString(temp, "EBusinessID");
	        LogisticsAction.AppKey=BaseUtil.getJsonString(temp, "AppKey");
	}

}